package com.mitu.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileChannel02 {
    public static void main(String[] args) throws IOException {
        //创建文件输入流
        FileInputStream fileInputStream=new FileInputStream("file01.txt");
        //创建对应的输入流

        //创建FileChannel
        FileChannel fileChannel=fileInputStream.getChannel();
        //创建缓冲区
        ByteBuffer buffer=ByteBuffer.allocate(12);
        //将FileChannel中的数据读到缓冲区中
        fileChannel.read(buffer);
        //将字节转为字符换
        System.out.println(new String(buffer.array()));
        //关闭流
        fileInputStream.close();
    }
}
